from tornado.web import Application, StaticFileHandler
import os

import config
from views import index

class Environment:
    __is_inited__ = None

    def initialize(self):
        # 单例模式，实例化后不再进行
        if self.__is_inited__:
            return
        # 初始化redis
        self._init_redis_()
    
    def _init_redis_(self):
        # 在这里初始化reis
        pass


class Application(Application):
    def __init__(self):
        handlers = [
            (r"/main", index.MainHandler),
            (r"/(.*)", StaticFileHandler, {"path": os.path.join(
                os.path.dirname(__file__), "static"), "default_filename": "index.html"})
        ]
        super().__init__(handlers, **config.settings)
